<template>
	<view style="box-sizing: border-box" @touchmove.stop.prevent="() => {}">
		<view class="my-head">
			<u-icon name="arrow-left" size="18" color="#000000" @click="fnReturn"></u-icon>
		</view>
		<view class="contentBox">
			<view class="content">
				<image src="/static/image/my/qzz.png" class="image" v-if="type==='true'"></image>
				<image src="/static/image/my/zpz.png" class="image" v-else></image>
				<view class="shenfen">您当前身份为</view>
				<view class="sftext">{{type=='true'?'求职者':'招聘者'}}</view>
				<view class="btn" @click="qiehuan(type)" v-if="type=='true'">
					<view>切换为招聘者身份</view>
				</view>
				<view class="btn1" @click="qiehuan(type)" v-else>
					<view>切换为求职者身份</view>
				</view>
			</view>
		</view>

		<u-popup :show="zujian" mode="bottom" round="10" @close="close1" v-if="type">
			<view class="upopup">
				<view class="upopuptop">选择企业</view>
				<scroll-view scroll-y  class="upopupnr" v-if="promptDatalist.length > 0">
					<view class="upopupnrtext" v-for="(item, key) in promptDatalist" :key="key"
						@click="clicklist(item)">
						<image :src="URL + item.LogoPath" class="imgestext"></image>
						<text class="nartext">{{ item.FullName }}</text>
						<!-- <text v-show="item.Status==1" class="status1">已认证</text>
						<text v-show="item.Status==0" class="status2">未认证</text> -->
						<image v-show="item.Status == 1" src="/static/recruit/index/yrz.png" class="imgrz"></image>
						<image v-show="item.Status == 0" src="/static/recruit/index/rzz.png" class="imgrz"></image>
						<image v-show="item.Status == 2" src="/static/recruit/index/rzsb.png" class="imgrz"></image>
					</view>
				</scroll-view>
				<view class="upopupnr" v-else>
					<view class="upopupnrtext1" style="text-align: left; font-size: 32rpx; padding-top: 30rpx">
						<text class="nartext">当前账号还没有绑定企业，需要创建企业才能发布职位~</text>
					</view>
				</view>

				<view class="but">
					<text @click="clicklist('add')" class="upopupnrbut">{{
		    promptDatalist.length > 0 ? "创建新企业" : "创建企业"
		  }}</text>
				</view>
			</view>
		</u-popup>

		<u-popup :show="showrenzheng" mode="bottom" round="10" @close="close">
			<view class="upopup">
				<view class="upopuptop">提示</view>

				<view class="upopupnr">
					<view class="upopupnrtext1" style="text-align: left; font-size: 32rpx; padding-top: 30rpx">
						<text class="nartext">创建企业之前需要进行个人认证，快去认证吧~</text>
					</view>
				</view>

				<view class="but">
					<view @click="clickrenzheng" class="upopupnrbut">去认证</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import myHead from '@/pages/component/baseHead.vue'
	export default {
		components: {
			myHead,
		},
		data() {
			return {
				type: null,
				transparent: 'transparent',
				color: '#FFFFFF',
				zujian: false,
				showrenzheng: false,
				promptDatalist: [],
				URL: this.$config.domain.staticUrl,
			}
		},
		onLoad(option) {
			if (option) {
				this.type = option.type
			}
			console.log(typeof(option.type))
		},
		methods: {
			fnReturn() {
				uni.navigateBack();
			},
			qiehuan(type) {
				console.log(type);
				if (type == 'true') {
					console.log("111111");
					this.zujian = true
					this.promplistdata()
				} else {
					console.log("2222222");
					let e = {
						EnCode: "-1",
						FullName: "切换个人",
						Id: "-1",
						ShortName: "我的",
						Status: "-1",
						ztcolor: "#ffffff",
					};
					if (e.Id == -1) {
						this.zujian = false;
						// 请求切换
						this.qihuanjushe();
					} else {
						this.qihuanjushe(e.Id);
						this.zujian = false;
					}
				}

			},
			promplistdata() {
				if (this.type) {
					// 个人
					const app = getApp();

					let qiyielist =  uni.getStorageSync('homelist').CorpList;
					// app.globalData.corps;

					if (qiyielist.length > 0) {
						qiyielist.forEach((res) => {
							res.ztcolor = "#ffffff";
						});
						this.promptDatalist = [...qiyielist];
					}
				} else {
					const app = getApp();
					let qiyielist = app.globalData.corps; //uni.getStorageSync('homelist').CorpList;
					if (qiyielist.length > 0) {
						qiyielist.forEach((res) => {
							res.ztcolor = "#ffffff";
							if (res.Id == app.globalData.userCorpId) {
								this.CorpFullName = res.FullName;
							}
						});
						this.promptDatalist = [...qiyielist];
					}
				}
			},
			// 点击企业
			clicklist(e) {
				let app = getApp()
				console.log(e);
				if (e == "add") {
					if (
						app.globalData.user.Status === null ||
						app.globalData.user.Status === 0 ||
						app.globalData.user.Status === 2
					) {
						this.zujian = false;
						this.showrenzheng = true;
					} else {
						uni.navigateTo({
							url: "/pages/views/packageB/type-recruit/jibenshezhi/renzhen/qiyei_renzheng",
						});
						this.zujian = false;
					}
				} else if (e.Status === 0 || e.Status === 2) {
					uni.navigateTo({
						url: "/pages/views/packageB/type-recruit/jibenshezhi/renzhen/qiyei_renzheng?ids=" +
							e.Id,
					});
				} else {
					this.zujian = false
					this.qihuanjushe(e.Id);
				}
			},


			// 切换身份
			qihuanjushe(itemid) {
				let that = this;
				let obj = {
					CurrentRole: "",
					CurrentCorpId: "",
				};
				if (this.type) {
					if (itemid) {
						//招聘者
						obj = {
							CurrentRole: 1,
							CurrentCorpId: itemid,
						};
					} else {
						// 切换成 个人
						obj = {
							CurrentRole: 0,
							CurrentCorpId: null,
						};
					}
				}


				console.log("obj", obj);
				// 当前角色 0求职者 1招聘者

				this.$http.core.changCurrentRole(obj).then(async (res) => {
					if (res.Success) {
						// //tim退出登录
						await this.$util.timlogout();
						this.$util.currentUser().then(() => {
							this.$util.setCustomTabbar();
							uni.reLaunch({
								url: "/pages/entry/index",
							});
						});
					}
				});
			},

			clickrenzheng() {
				let app = getApp()
				if (app.globalData.user.Status === 0 || app.globalData.user.Status === 2) {
					uni.navigateTo({
						url: "/pages/views/packageB/type-jobhunting/jibenshezhi/jibenziliao/shimingjieguo?status=" +
							app.globalData.user.Status,
					});
				} else {
					uni.navigateTo({
						url: "/pages/views/packageB/type-jobhunting/jibenshezhi/jibenziliao/shimingrenzheng",
					});
				}

				this.close();
			},
			open() {
				this.showrenzheng = true;
			},
			close() {
				this.showrenzheng = false;
			},
			close1() {
				this.zujian = false;
			},
		}
	}
</script>

<style scoped lang="scss">
	.my-head {
		position: fixed;
		top: 0;
		width: 100%;
		padding: var(--status-bar-height) 30rpx 0;
		height: calc(88rpx + var(--status-bar-height));
		display: flex;
		justify-content: space-between;
		align-items: center;
		box-sizing: border-box;

	}

	.contentBox {
		background-image: url("/static/image/my/loginbg.png");
		background-repeat: no-repeat;
		background-size: cover;
		height: 100vh;
		width: 100%;

		.content {
			padding: 230rpx 60rpx 0;
			text-align: center;

			.image {
				width: 600rpx;
				height: 620rpx;
			}

			.shenfen {
				font-size: 28rpx;
				font-weight: 400;
				color: #999999;
				padding-top: 94rpx;
			}

			.sftext {
				font-size: 36rpx;
				font-weight: 700;
				color: #001146;
				padding: 9rpx 0 174rpx;
			}

			.btn {
				background: #FF5574;
				border-radius: 10rpx;
				opacity: 1;
				padding: 24rpx 179rpx;

				view {
					font-size: 30rpx;
					font-weight: 400;
					color: #FFFFFF;
				}
			}

			.btn1 {

				background: #3476FE;
				border-radius: 10rpx;
				opacity: 1;
				padding: 24rpx 179rpx;

				view {
					font-size: 30rpx;
					font-weight: 400;
					color: #FFFFFF;
				}
			}
		}
	}

	.upopup {
		padding: 20rpx 50rpx;
		// width: 600rpx;
		text-align: center;

		.upopuptop {
			padding: 20rpx;
			font-size: 36rpx;
		}

		.upopupnr {
			margin: 30rpx 0rpx;
			height: 300rpx;
			overflow-y: auto;

			.upopupnrtext {
				padding: 10rpx 40rpx;
				display: flex;
				justify-content: inherit;
				align-items: center;

				.imgestext {
					width: 40rpx;
					height: 40rpx;
				}

				.nartext {
					padding: 10rpx 20rpx;
					font-size: 34rpx;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					width: 64%;
					text-align: left;
				}

				.status1 {
					color: #165dff;
					border-radius: 10rpx;
					padding: 5rpx 20rpx;
					font-size: 24rpx;
					background-color: #f2f2f2;
				}

				.status2 {
					color: #00000085;
					border-radius: 10rpx;
					padding: 5rpx 20rpx;
					font-size: 24rpx;
					background-color: #f2f2f2;
				}

				.imgrz {
					width: 108rpx;
					height: 32rpx;
				}
			}
		}

		.but {
			.upopupnrbut {
				padding: 24rpx 32rpx;
				background-color: #1684fc;
				border-radius: 10rpx;
				color: #ffffff;
				display: inline-block;
				width: 90%;
			}
		}
	}
</style>